From 85a539ce6d42cea52970c7c22d35538443e54937 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 12 Nov 2014 22:50:52 -0500 Subject: [PATCH] inspector: Add frame clock info Add the frame clocks of toplevel widgets to the object tree, and show their frame count and frame rate in the misc tab. --- gtk/inspector/misc-info.c | 57 ++++++++++++++++++++++++++++++ gtk/inspector/misc-info.ui | 68 ++++++++++++++++++++++++++++++++++++ gtk/inspector/misc-info.ui.h | 2 ++ gtk/inspector/object-tree.c | 9 +++++ 4 files changed, 136 insertions(+) diff --git a/gtk/inspector/misc-info.c b/gtk/inspector/misc-info.c index 08343119f0..323f6d5e1d 100644 --- a/gtk/inspector/misc-info.c +++ b/gtk/inspector/misc-info.c @@ -56,6 +56,10 @@ struct _GtkInspectorMiscInfoPrivate { GtkWidget *clip_area; GtkWidget *tick_callback_row; GtkWidget *tick_callback; + GtkWidget *framerate_row; + GtkWidget *framerate; + GtkWidget *framecount_row; + GtkWidget *framecount; GtkWidget *accessible_role_row; GtkWidget *accessible_role; GtkWidget *mapped_row; @@ -68,6 +72,7 @@ struct _GtkInspectorMiscInfoPrivate { GtkWidget *child_visible; guint update_source_id; + gint64 last_frame; }; enum @@ -324,6 +329,43 @@ update_info (gpointer data) update_focus_widget (sl); } + if (GDK_IS_FRAME_CLOCK (sl->priv->object)) + { + GdkFrameClock *clock; + gint64 frame; + gint64 frame_time; + gint64 history_start; + gint64 history_len; + gint64 previous_frame_time; + GdkFrameTimings *previous_timings; + + clock = GDK_FRAME_CLOCK (sl->priv->object); + frame = gdk_frame_clock_get_frame_counter (clock); + frame_time = gdk_frame_clock_get_frame_time (clock); + + tmp = g_strdup_printf ("%ld", frame); + gtk_label_set_label (GTK_LABEL (sl->priv->framecount), tmp); + g_free (tmp); + + history_start = gdk_frame_clock_get_history_start (clock); + history_len = frame - history_start; + + if (history_len > 0 && sl->priv->last_frame != frame) + { + previous_timings = gdk_frame_clock_get_timings (clock, history_start); + previous_frame_time = gdk_frame_timings_get_frame_time (previous_timings); + tmp = g_strdup_printf ("%4.1f ⁄ s", (G_USEC_PER_SEC * history_len) / (double) (frame_time - previous_frame_time)); + gtk_label_set_label (GTK_LABEL (sl->priv->framerate), tmp); + g_free (tmp); + } + else + { + gtk_label_set_label (GTK_LABEL (sl->priv->framerate), "—"); + } + + sl->priv->last_frame = frame; + } + return G_SOURCE_CONTINUE; } @@ -402,6 +444,17 @@ gtk_inspector_misc_info_set_object (GtkInspectorMiscInfo *sl, gtk_widget_hide (sl->priv->focus_widget_row); } + if (GDK_IS_FRAME_CLOCK (object)) + { + gtk_widget_show (sl->priv->framecount_row); + gtk_widget_show (sl->priv->framerate_row); + } + else + { + gtk_widget_hide (sl->priv->framecount_row); + gtk_widget_hide (sl->priv->framerate_row); + } + update_info (sl); } @@ -511,6 +564,10 @@ gtk_inspector_misc_info_class_init (GtkInspectorMiscInfoClass *klass) gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, clip_area); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, tick_callback_row); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, tick_callback); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framecount_row); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framecount); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framerate_row); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framerate); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, accessible_role_row); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, accessible_role); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, mapped_row); diff --git a/gtk/inspector/misc-info.ui b/gtk/inspector/misc-info.ui index 4eeba49c8c..d0a7966414 100644 --- a/gtk/inspector/misc-info.ui +++ b/gtk/inspector/misc-info.ui @@ -342,6 +342,74 @@ + + + true + false + + + true + horizontal + 10 + 40 + + + true + Frame count + start + baseline + 0 + + + true + + + + + true + end + baseline + + + + + + + + + + true + false + + + true + horizontal + 10 + 40 + + + true + Frame rate + start + baseline + 0 + + + true + + + + + true + end + baseline + + + + + + + true diff --git a/gtk/inspector/misc-info.ui.h b/gtk/inspector/misc-info.ui.h index 53fba2b42a..a09a285e51 100644 --- a/gtk/inspector/misc-info.ui.h +++ b/gtk/inspector/misc-info.ui.h @@ -9,6 +9,8 @@ N_("Mnemonic Label"); N_("Allocated size"); N_("Clip area"); N_("Tick callback"); +N_("Frame count"); +N_("Frame rate"); N_("Accessible role"); N_("Mapped"); N_("Realized"); diff --git a/gtk/inspector/object-tree.c b/gtk/inspector/object-tree.c index 6f7d0bc513..000db9171b 100644 --- a/gtk/inspector/object-tree.c +++ b/gtk/inspector/object-tree.c @@ -780,6 +780,15 @@ gtk_inspector_object_tree_append_object (GtkInspectorObjectTree *wt, } g_list_free (list); } + + if (gtk_widget_is_toplevel (GTK_WIDGET (object))) + { + GObject *clock; + + clock = (GObject *)gtk_widget_get_frame_clock (GTK_WIDGET (object)); + if (clock) + gtk_inspector_object_tree_append_object (wt, clock, &iter, "frame-clock"); + } } } -- 2.30.2